$('#top').load('top.html');
$('#bottom').load('bottom.html');
// ---

$('.btn').click(() => {
  const name = $('#username').val()
  const pwd = $('#password').val()

  var data = {
    username: name,
    password: pwd
  }

  if (!name || !pwd) return alert('请填写完整~')

  $.post('http://localhost:8080/php/login.php', data, res => {
    console.log(res);

    if (res.code === 0) {
      return alert(`${res.message}`)
    }

    window.localStorage.setItem('login', 1)
    window.localStorage.setItem('token', res.token)
    // window.localStorage.setItem('id', res.user.id)
    const url = window.localStorage.getItem('url')
    window.localStorage.removeItem('url')
    window.location.href = `./${url ? url : 'index'}.html`

  }, 'json')
})
